package com.xinziruo.richclient.util.filecommand.impl;

import java.io.File;

import org.apache.commons.io.FileUtils;

import com.xinziruo.richclient.util.ExceptionUtils;
import com.xinziruo.richclient.util.filecommand.FileCommand;

/**
 * 
 * 
 * @author loudyn.
 */
public class WriteStringToFileCommand implements FileCommand {
	private final File target;
	private final String data;
	private final String encoding;

	/**
	 * 
	 * @param target
	 * @param data
	 * @param encoding
	 */
	public WriteStringToFileCommand(File target, String data, String encoding) {
		this.target = target;
		this.data = data;
		this.encoding = encoding;
	}

	/**
	 * 
	 * @param target
	 * @param data
	 * @param encoding
	 */
	public WriteStringToFileCommand(String target, String data, String encoding) {
		this(new File(target), data, encoding);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.youboy.module.util.filecommand.FileCommand#execute()
	 */
	public void execute() {

		try {

			FileUtils.writeStringToFile(target, data, encoding);
		} catch (Exception e) {
			throw ExceptionUtils.toUnchecked(e);
		}
	}
}
